package lex.expression.ui;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class TitledPane extends JPanel {
	private static final String DEFAULT_TITLE = "Title";

	private JLabel titleLabel = null;
	private JScrollPane scrollPane = null;
	private JTextArea textArea = null;

	public TitledPane() {
		this(DEFAULT_TITLE);
	}

	public TitledPane(String title) {
		super();
		initialize();
		this.getTitleLabel().setText(title);
	}

	private void initialize() {

		this.setSize(300, 200);
		this.setLayout(new BorderLayout());
		this.add(getTitleLabel(), BorderLayout.NORTH);
		this.add(getScrollPane(), BorderLayout.CENTER);
	}

	public JLabel getTitleLabel() {
		if (null == this.titleLabel) {
			titleLabel = new JLabel();
		}
		return this.titleLabel;
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTextArea());
		}
		return scrollPane;
	}

	public JTextArea getTextArea() {
		if (textArea == null) {
			textArea = new JTextArea();
		}
		return textArea;
	}
}
